<template>
  <div>
    <FixedOperation>
      <div class="flex items-center justify-between">
        <span>{{
          router.currentRoute.value.query.flag == 'add'
            ? '新增客户'
            : '编辑客户'
        }}</span>
        <!-- 内容 -->
        <div class="text-right">
          <slot></slot>
          <el-button
            type="primary"
            plain
            @click="juageFlow"
            v-if="
              form.bizCustomerAddDto.customerType.includes('2') &&
              isExamine &&
              isCanStart
            "
            >提交审批
          </el-button>
          <el-button type="primary" @click="save" :loading="btnLoading"
            >保存
          </el-button>

          <el-button type="danger" @click="close">关闭</el-button>
        </div>
      </div>
    </FixedOperation>

    <div class="px-10">
      <el-form
        :model="form"
        :rules="rules"
        label-width="130"
        ref="formRef"
        label-position="right"
      >
        <el-collapse v-model="activeNames">
          <el-collapse-item name="info">
            <template #title>
              <title-name title="基本信息" icon="i-carbon-bookmark-filled" />
            </template>
            <el-row :gutter="formGutter" class="p-10">
              <el-col :span="formCol">
                <el-form-item
                  label="企业名称："
                  prop="bizCustomerAddDto.customerName"
                >
                  <el-input
                    v-model="form.bizCustomerAddDto.customerName"
                    placeholder="填写企业名称"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="客户类别："
                  prop="bizCustomerAddDto.customerType"
                >
                  <!-- 客户类别 -->
                  <el-select
                    class="w-full"
                    v-model="form.bizCustomerAddDto.customerType"
                    placeholder="客户类别"
                    multiple
                    @change="customerTypeChange"
                  >
                    <el-option
                      v-for="(dict, index) in customer_class"
                      :key="index"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="联系人："
                  prop="bizCustomerAddDto.mainContactName"
                >
                  <el-input
                    v-model="form.bizCustomerAddDto.mainContactName"
                    placeholder="填写联系人姓名"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="企业税号："
                  prop="bizCustomerAddDto.customerTaxcode"
                >
                  <el-input
                    maxlength="20"
                    v-model="form.bizCustomerAddDto.customerTaxcode"
                    placeholder="填写企业税号"
                    @blur="checkTaxcode"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="尊称：">
                  <el-radio-group v-model="form.bizContactDto.sex">
                    <el-radio
                      v-for="(item, index) in sys_user_sex"
                      :label="item.value"
                      :key="index"
                    >
                      {{ item.label }}
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="联系电话："
                  prop="bizCustomerAddDto.mainContactPhone"
                >
                  <el-input
                    v-model="form.bizCustomerAddDto.mainContactPhone"
                    placeholder="填写联系电话"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="注册资本："
                  prop="bizCustomerExtDto.registerCap"
                >
                  <el-input
                    type="number"
                    v-model="form.bizCustomerExtDto.registerCap"
                    placeholder="输入金额"
                  >
                    <template #append>万元</template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="所属税务机关："
                  prop="bizCustomerAddDto.taxdeptCode"
                >
                  <el-tree-select
                    style="width: 100%"
                    v-model="form.bizCustomerAddDto.taxdeptCode"
                    :data="taxTreeData"
                    :check-strictly="true"
                    :props="{
                      value: 'id',
                      label: 'label',
                      children: 'children'
                    }"
                    node-key="id"
                    placeholder="填写所属税务机关"
                    value-key="id"
                    filterable
                  />
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="业务分类"
                  prop="bizCustomerAddDto.businessTypeArr"
                >
                  <el-tree-select
                    style="width: 100%"
                    v-model="form.bizCustomerAddDto.businessTypeArr"
                    :data="userBusinessTypeOption"
                    :multiple="true"
                    :check-strictly="false"
                    :show-checkbox="true"
                    placeholder="请选择业务分类"
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <!--    代账公司      -->
          <el-collapse-item
            name="agency"
            v-if="form.bizCustomerAddDto.customerType.includes('4')"
          >
            <template #title>
              <title-name
                title="代账公司特殊信息"
                icon="i-carbon-bookmark-filled"
              />
            </template>
            <el-row :gutter="formGutter" class="p-10">
              <el-col :span="24">
                <el-form-item label="授权码" label-width="160">
                  <el-input
                    v-model="form.bizCustomerExtDto.agentAuthorizationCode"
                    placeholder="请输入授权码"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="星级授牌时间" label-width="160">
                  <el-date-picker
                    style="width: 100%"
                    v-model="form.bizCustomerExtDto.agentStarAwardSdate"
                    type="date"
                    value-format="YYYY-MM-DD 00:00:00"
                    format="YYYY-MM-DD"
                    placeholder="请选择日期"
                  />
                </el-form-item>
              </el-col>

              <el-col :span="formCol">
                <el-form-item label="星级授牌到期时间" label-width="160">
                  <el-date-picker
                    style="width: 100%"
                    v-model="form.bizCustomerExtDto.agentStarAwardEdate"
                    type="date"
                    value-format="YYYY-MM-DD 00:00:00"
                    format="YYYY-MM-DD"
                    placeholder="请选择日期"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="代账公司每户分润金额" label-width="160">
                  <el-input
                    v-model="form.bizCustomerExtDto.agentShareMoney"
                    placeholder="输入金额"
                  >
                    <template #append>元</template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="代账公司每户收取金额" label-width="160">
                  <el-input
                    v-model="form.bizCustomerExtDto.agentIncomeMoney"
                    placeholder="输入金额"
                  >
                    <template #append>元</template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="代账公司合同上传" label-width="160">
                  <el-upload
                    class="upload-demo"
                    action="#"
                    :http-request="
                      params => {
                        handleFileChange(params, 'file')
                      }
                    "
                    accept=".rar, .zip, .doc, .docx, .pdf"
                    :show-file-list="false"
                  >
                    <el-button type="primary" style="font-size: 14px">
                      <el-icon>
                        <UploadFilled />
                      </el-icon>
                      上传合同
                    </el-button>
                    <template #tip>
                      <div class="el-upload__tip">
                        支持格式：.rar .zip .doc .docx .pdf
                        ，单个文件不能超过20MB
                      </div>
                    </template>
                  </el-upload>
                  <div class="text-14px mt-10px" style="width: 100%">
                    <div v-for="(item, index) in fileList" :key="item.fileId">
                      <a :href="item.url">{{ item.origFileName }}</a>
                      <el-button text plain @click="delFileName(index, 'file')"
                        >删除
                      </el-button>
                    </div>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="代账公司授牌照片上传" label-width="160">
                  <el-upload
                    class="upload-demo"
                    action="#"
                    :http-request="
                      params => {
                        handleFileChange(params, 'pic')
                      }
                    "
                    accept=".jpg,.jpeg,.png"
                    :show-file-list="false"
                  >
                    <el-button type="primary" style="font-size: 14px">
                      <el-icon>
                        <UploadFilled />
                      </el-icon>
                      上传照片
                    </el-button>
                    <template #tip>
                      <div class="el-upload__tip">
                        支持格式：.jpg,.jpeg,.png ，单个文件不能超过20MB
                      </div>
                    </template>
                  </el-upload>
                  <div class="text-14px mt-10px" style="width: 100%">
                    <div v-for="(item, index) in picList" :key="item.fileId">
                      <a :href="item.url">{{ item.origFileName }}</a>
                      <el-button text plain @click="delFileName(index, 'pic')"
                        >删除
                      </el-button>
                    </div>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="合作产品" label-width="160">
                  <!-- 合作产品 -->
                  <el-select
                    class="w-full"
                    v-model="form.bizCustomerExtDto.agentBusinessTypeId"
                    placeholder="合作产品"
                    multiple
                  >
                    <el-option
                      v-for="(dict, index) in business_classification"
                      :key="index"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item name="append">
            <template #title>
              <title-name title="附加信息" icon="i-carbon-bookmark-filled" />
            </template>
            <el-row :gutter="formGutter" class="p-10">
              <el-col :span="formCol">
                <el-form-item
                  label="纳税人性质："
                  prop="bizCustomerAddDto.taxNature"
                >
                  <el-select
                    class="w-full"
                    v-model="form.bizCustomerAddDto.taxNature"
                    placeholder="请选择纳税人性质"
                  >
                    <el-option
                      v-for="(dict, index) in tax_grade"
                      :key="index"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="客户等级："
                  prop="bizCustomerAddDto.customerLevel"
                >
                  <el-select
                    v-model="form.bizCustomerAddDto.customerLevel"
                    placeholder="请选择客户等级"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in customer_level"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="所属企业："
                  prop="bizCustomerAddDto.parentId"
                >
                  <el-select
                    v-model="form.bizCustomerAddDto.parentId"
                    placeholder="请输入所属企业关键字"
                    class="w-full"
                    filterable
                    remote
                    :remote-method="queryCustomer"
                  >
                    <el-option
                      v-for="item in parentOptions"
                      :key="item.id"
                      :label="item.customerName"
                      :value="item.id"
                    >
                      <div>
                        <span>{{ item.customerName }}</span>
                      </div>
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="formCol">
                <el-form-item
                  label="归属公司："
                  required
                  prop="bizCustomerAddDto.orgId"
                >
                  <el-tree-select
                    style="width: 100%"
                    v-model="form.bizCustomerAddDto.orgId"
                    :data="companyOptions"
                    :props="{
                      value: 'id',
                      label: 'label',
                      children: 'children'
                    }"
                    placeholder="请选择归属公司"
                    value-key="id"
                    filterable
                    :disabled="userStore.user.orgId != '484'"
                    @change="orgChange"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="行业类型："
                  prop="bizCustomerAddDto.industryTypeCode"
                >
                  <el-select
                    v-model="form.bizCustomerAddDto.industryTypeCode"
                    placeholder="请选择行业类型"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in industry_category"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="归属人员："
                  prop="bizCustomerAddDto.userId"
                >
                  <el-select
                    v-model="form.bizCustomerAddDto.userId"
                    placeholder="请选择归属人员"
                    @focus="userInputFocus"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in selectOptionObj['userId']"
                      :key="index"
                      :label="item.label"
                      :value="item.uuid"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="数电配置：">
                  <el-radio-group
                    v-model="form.bizCustomerExtDto.isDigital"
                    class="ml-4"
                    @change="digitalChange"
                  >
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                  </el-radio-group>

                  <el-select
                    v-if="form.bizCustomerExtDto.isDigital == 1"
                    v-model="form.bizCustomerExtDto.digitalInfo"
                    class="w-full"
                    placeholder="请选择数电信息"
                    style="width: 50%; margin-left: 20px"
                  >
                    <el-option
                      v-for="(item, index) in biz_digital_info"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="星级：">
                  <el-rate v-model="form.bizCustomerAddDto.starRating" />
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="客户状态："
                  prop="bizCustomerAddDto.status"
                >
                  <el-select
                    v-model="form.bizCustomerAddDto.status"
                    placeholder="请选择客户状态"
                    class="w-full"
                    @change="statusChange"
                  >
                    <el-option
                      v-for="(item, index) in customer_status"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="信用等级："
                  prop="bizCustomerExtDto.creditListId"
                >
                  <el-select
                    v-model="form.bizCustomerExtDto.creditListId"
                    placeholder="请选择信用等级"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in credit_rating"
                      :key="index"
                      :label="item.label"
                      :value="item.value * 1"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="客户来源："
                  prop="bizCustomerAddDto.origin"
                >
                  <el-select
                    v-model="form.bizCustomerAddDto.origin"
                    placeholder="请选择客户来源"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in customer_source"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="征信积分："
                  prop="bizCustomerExtDto.creditScore"
                >
                  <el-input
                    v-model="form.bizCustomerExtDto.creditScore"
                    placeholder="请输入征信积分"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="所在城市："
                  prop="bizCustomerAddDto.cityCode"
                >
                  <el-cascader
                    class="w-full"
                    clearable
                    placeholder="请选择地址"
                    style="width: 100%"
                    :options="regionData"
                    v-model="form.bizCustomerAddDto.cityCode"
                    @change="cityChange"
                  >
                  </el-cascader>
                </el-form-item>
              </el-col>

              <el-col :span="formCol">
                <el-form-item label="企业规模：">
                  <el-input
                    v-model="form.bizCustomerExtDto.scale"
                    placeholder="请输入企业规模"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="地址说明："
                  prop="bizCustomerExtDto.addressName"
                >
                  <el-input
                    v-model="form.bizCustomerExtDto.addressName"
                    placeholder="请输入地址说明,如：办公、注册、分机"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="详细地址："
                  prop="bizCustomerExtDto.address"
                >
                  <el-input
                    v-model="form.bizCustomerExtDto.address"
                    placeholder="请输入详细地址"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注信息：">
                  <el-input
                    type="textarea"
                    rows="2"
                    v-model="form.bizCustomerExtDto.remarks"
                    placeholder="请输入备注信息"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item name="contacts">
            <template #title>
              <title-name title="联系人详情" icon="i-carbon-bookmark-filled" />
            </template>
            <el-row :gutter="formGutter" class="p-10">
              <el-col :span="formCol">
                <el-form-item label="岗位：" prop="bizContactDto.postCode">
                  <el-select
                    v-model="form.bizContactDto.postCode"
                    placeholder="请选择岗位"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in post_dict"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="QQ号码：">
                  <el-input
                    v-model="form.bizContactExtDto.qq"
                    placeholder="请输入QQ号码"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="职务：">
                  <el-select
                    v-model="form.bizContactDto.dutyCode"
                    placeholder="请选择职务"
                    class="w-full"
                  >
                    <el-option
                      v-for="(item, index) in duties_dict"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="微信账号：">
                  <el-input
                    v-model="form.bizContactExtDto.wechat"
                    placeholder="请输入微信账号"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="生日：">
                  <el-date-picker
                    style="width: 100%"
                    v-model="form.bizContactDto.birthday"
                    type="date"
                    value-format="YYYY-MM-DD 00:00:00"
                    format="YYYY-MM-DD"
                    placeholder="请选择日期"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="微信昵称：">
                  <el-input
                    v-model="form.bizContactExtDto.wechatName"
                    placeholder="请输入微信昵称"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="固定电话：">
                  <el-input
                    v-model="form.bizContactDto.telephone"
                    placeholder="请输入固定电话"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="所在群：">
                  <el-input
                    v-model="form.bizContactExtDto.chatGroup"
                    placeholder="请输入所在群"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="传真号码：">
                  <el-input
                    v-model="form.bizContactExtDto.fax"
                    placeholder="请输入传真号码"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="详细地址：">
                  <el-input
                    v-model="form.bizContactDto.address"
                    placeholder="请输入详细地址"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="电子邮箱：">
                  <el-input
                    v-model="form.bizContactExtDto.email"
                    placeholder="请输入电子邮箱"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item name="finance">
            <template #title>
              <title-name title="财务信息" icon="i-carbon-bookmark-filled" />
            </template>
            <el-row :gutter="formGutter" class="p-10">
              <el-col :span="formCol">
                <el-form-item label="财务软件品牌：">
                  <el-input
                    v-model="form.bizCustomerExtDto.fdinfoSoftwareBrand"
                    placeholder="请输入财务软件品牌"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="财务软件版本号：">
                  <el-input
                    v-model="form.bizCustomerExtDto.fdinfoSoftwareVersion"
                    placeholder="请输入财务软件版本号"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="开票额（元）：">
                  <el-input
                    v-model="form.bizCustomerExtDto.fdinfoIssueAmount"
                    placeholder="请输入开票额"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="开票量：">
                  <el-input
                    v-model="form.bizCustomerExtDto.fdinfoIssueCount"
                    placeholder="请输入开票量"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="财务人员：">
                  <el-input
                    v-model="form.bizCustomerExtDto.fdinfoPersonCount"
                    placeholder="请输入财务人员"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item name="invoice">
            <template #title>
              <title-name title="开票信息" icon="i-carbon-bookmark-filled" />
            </template>
            <el-row :gutter="formGutter" class="p-10">
              <el-col :span="formCol">
                <el-form-item label="是否开票：">
                  <el-radio-group
                    v-model="form.bizCustomerExtDto.isIssueInv"
                    class="ml-4"
                  >
                    <el-radio
                      v-for="item in sys_yes_no"
                      :key="item.value"
                      :label="item.value"
                      >{{ item.label }}
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="是否诺诺开票：">
                  <el-radio-group
                    v-model="form.bizCustomerExtDto.isIssueInvNuonuo"
                    class="ml-4"
                  >
                    <el-radio
                      v-for="item in sys_yes_no"
                      :key="item.value"
                      :label="item.value"
                      >{{ item.label }}
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="是否51开票：">
                  <el-radio-group
                    v-model="form.bizCustomerExtDto.isIssueInv51"
                    class="ml-4"
                  >
                    <el-radio
                      v-for="item in sys_yes_no"
                      :key="item.value"
                      :label="item.value"
                      >{{ item.label }}
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item name="bill">
            <template #title>
              <title-name title="开票抬头" icon="i-carbon-bookmark-filled" />
            </template>
            <el-row :gutter="formGutter" class="px-10">
              <el-col :span="formCol">
                <el-form-item
                  label="发票类型"
                  prop="bizCustomerInvinfoDto.invoiceType"
                >
                  <el-radio-group
                    v-model="form.bizCustomerInvinfoDto.invoiceType"
                  >
                    <el-radio-button
                      v-for="(item, index) in invoice_type"
                      :label="item.value"
                      :key="index"
                      >{{ item.label }}
                    </el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <!--    发票类型为电子普通发票 start      -->
            <el-row
              v-if="form.bizCustomerInvinfoDto.invoiceType == '1'"
              :gutter="formGutter"
              class="px-10"
            >
              <el-col :span="formCol">
                <el-form-item
                  label="发票抬头"
                  prop="bizCustomerInvinfoDto.headerType"
                >
                  <el-radio-group
                    v-model="form.bizCustomerInvinfoDto.headerType"
                  >
                    <el-radio-button
                      v-for="(item, index) in invoice_header"
                      :label="item.value"
                      :key="index"
                      >{{ item.label }}
                    </el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <!--    发票类型为电子普通发票 end      -->
            <el-row
              v-if="
                form.bizCustomerInvinfoDto.headerType == '1' ||
                form.bizCustomerInvinfoDto.invoiceType == '2'
              "
              :gutter="formGutter"
              class="px-10"
            >
              <el-col :span="formCol">
                <el-form-item
                  label="企业名称"
                  prop="bizCustomerInvinfoDto.taxName"
                >
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.taxName"
                    placeholder="请输入企业名称"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="企业税号"
                  prop="bizCustomerInvinfoDto.taxCode"
                >
                  <el-input
                    maxlength="20"
                    v-model="form.bizCustomerInvinfoDto.taxCode"
                    placeholder="请输入企业税号"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="企业地址"
                  prop="bizCustomerInvinfoDto.taxAddress"
                >
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.taxAddress"
                    placeholder="请输入企业地址"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="开户银行"
                  prop="bizCustomerInvinfoDto.bank"
                >
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.bank"
                    placeholder="请输入开户银行"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="企业电话"
                  prop="bizCustomerInvinfoDto.taxPhone"
                >
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.taxPhone"
                    placeholder="请输入企业电话"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item
                  label="银行账号"
                  prop="bizCustomerInvinfoDto.bankNum"
                >
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.bankNum"
                    placeholder="请输入银行账号"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <!--   发票抬头：个人-->
            <el-row
              v-if="
                form.bizCustomerInvinfoDto.headerType == '2' &&
                form.bizCustomerInvinfoDto.invoiceType == '1'
              "
              :gutter="formGutter"
              class="px-10"
            >
              <el-col :span="formCol">
                <el-form-item
                  label="个人名称"
                  prop="bizCustomerInvinfoDto.taxName"
                >
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.taxName"
                    placeholder="请输入个人名称"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="formGutter" class="px-10">
              <el-col :span="formCol">
                <el-form-item>
                  <template #label>
                    <span class="font-bold">收票人信息</span>
                  </template>
                </el-form-item>
              </el-col>
            </el-row>
            <!--     发票类型为电子普通发票     -->
            <el-row
              v-if="form.bizCustomerInvinfoDto.invoiceType == '1'"
              :gutter="formGutter"
              class="px-10"
            >
              <el-col :span="formCol">
                <el-form-item label="收票人手机">
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.receivePhone"
                    placeholder="请输入收票人手机"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="收票人邮箱">
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.receiveEmail"
                    placeholder="请输入收票人邮箱"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <!--     发票类型为增值税专用发票    -->

            <el-row
              v-if="form.bizCustomerInvinfoDto.invoiceType == '2'"
              :gutter="formGutter"
              class="px-10"
            >
              <el-col :span="formCol">
                <el-form-item label="收票人姓名">
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.receiveName"
                    placeholder="请输入收票人姓名"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="收票人电话">
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.receivePhone"
                    placeholder="请输入收票人电话"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="formCol">
                <el-form-item label="收票人地址">
                  <el-input
                    v-model="form.bizCustomerInvinfoDto.receiveAddress"
                    placeholder="请输入收票人地址"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="formGutter" class="px-10">
              <el-col :span="formCol">
                <el-form-item>
                  <template #label>
                    <span class="font-bold">发票内容</span>
                  </template>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="formGutter" class="px-10">
              <el-col :span="formCol">
                <el-form-item
                  label="发票内容"
                  prop="bizCustomerInvinfoDto.invContentType"
                >
                  <el-radio-group
                    v-model="form.bizCustomerInvinfoDto.invContentType"
                  >
                    <el-radio-button label="1">商品明细</el-radio-button>
                    <el-radio-button label="2">商品类型</el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <!--  弹窗选择组件  -->
      <SelectDialog :dialog-param="dialogParam" @ok="selectData"></SelectDialog>
      <!-- 提交审批 -->
      <SubmissionProcess
        :dialog-param="examineParam"
        :flowOptions="flowOptions"
        @initiate="handleClose('initiate')"
        @close="handleClose('examine')"
      ></SubmissionProcess>
    </div>
  </div>
</template>
<script setup name="CustomerAddOrUpdate">
import { getCurrentInstance } from 'vue'
import FixedOperation from '@/components/FixedOperation'
import { regionData, CodeToText, TextToCode } from 'element-china-area-data'
import useTagsViewStore from '@/store/modules/tagsView'
import useCommonStore from '@/store/modules/common'
import SubmissionProcess from '@/businessComponents/SubmissionProcess'

import {
  userBusinessTypeOption //用户业务类型树
} from '@/hooks/dict/order'
import { validatePhoneTwo } from '@/utils/validate'
import {
  createCustomer,
  updateCustomer,
  getCustomerInfo,
  getCustomerEditInfo,
  getCustomerList,
  getListByCustomerName,
  checkCustomerTaxCode
} from '@/api/customerManage/customerList'
import { treeselect, treeselectNoPriv } from '@/api/rsgl/zzjg'
import useUserStore from '@/store/modules/user'
import {
  getPricipalId,
  getTreeNodeByParam,
  getUniqueUserId
} from '@/utils/commo'
import { formatDate } from '@/utils'
import { delFile, uploadFile } from '@/api/salesManage/contractManage'
import { getBusinessProStatus, listProcess } from '@/api/workflow/process'

// 通用数据store
const commonStore = useCommonStore()
const userStore = useUserStore()
const { proxy } = getCurrentInstance()
const router = useRouter()
// 字典 具体查看根目录DICT.md文件
const {
  industry_category,
  customer_class,
  tax_grade,
  credit_rating,
  post_dict,
  duties_dict,
  customer_status,
  customer_source,
  invoice_type,
  invoice_header,
  sys_user_sex,
  customer_level,
  business_classification,
  sys_yes_no,
  biz_digital_info
} = proxy.useDict(
  'industry_category',
  'customer_class',
  'tax_grade',
  'credit_rating',
  'post_dict',
  'duties_dict',
  'customer_status',
  'customer_source',
  'invoice_type',
  'invoice_header',
  'sys_user_sex',
  'customer_level',
  'business_classification',
  'sys_yes_no',
  'biz_digital_info'
)
const activeNames = ref([
  'info',
  'append',
  'contacts',
  'finance',
  'invoice',
  'bill',
  'agency'
])
const data = reactive({
  form: {
    bizCustomerAddDto: {
      origin: '9',
      customerType: '3',
      customerLevel: '4'
    }, //客户信息
    bizCustomerExtDto: {}, //客户附加信息
    bizContactDto: {
      sex: '2'
    }, //联系人信息
    bizCustomerInvinfoDto: {
      invoiceType: '1',
      headerType: '1',
      invContentType: '1'
    }, //开票信息
    bizContactExtDto: {} //联系人扩展信息
  },
  dialogParam: {}, //弹窗组件配置
  selectOptionObj: {}, // select
  rules: {
    // 企业名称
    'bizCustomerAddDto.customerName': [
      { required: true, message: '请输入企业名称', trigger: 'blur' }
    ],
    // 客户类别
    'bizCustomerAddDto.customerType': [
      { required: true, message: '请选择客户类别', trigger: 'change' }
    ],
    // 联系人
    'bizCustomerAddDto.mainContactName': [
      { required: true, message: '请输入联系人姓名', trigger: 'blur' }
    ],
    // 归属人员
    'bizCustomerAddDto.userId': [
      { required: true, message: '请选择归属人员', trigger: 'change' }
    ],
    // 客户等级
    'bizCustomerAddDto.customerLevel': [
      { required: true, message: '请选择客户等级', trigger: 'change' }
    ],
    // 联系人电话
    'bizCustomerAddDto.mainContactPhone': [
      { required: true, validator: validatePhoneTwo, trigger: 'blur' }
    ],
    //企业名称
    // 'bizCustomerInvinfoDto.taxName': [
    //   { required: true, message: '请输入企业名称', trigger: 'change' }
    // ],
    //企业税号
    'bizCustomerAddDto.customerTaxcode': [
      { required: true, message: '请输入企业税号', trigger: 'blur' }
    ],
    'bizCustomerAddDto.businessTypeArr': [
      { required: true, message: '请选择业务分类', trigger: 'change' }
    ],
    'bizCustomerAddDto.taxNature': [
      { required: true, message: '请选择纳税人性质', trigger: 'change' }
    ],
    // 详细地址
    'bizCustomerExtDto.address': [
      { required: true, message: '请输入详细地址', trigger: 'blur' }
    ],
    'bizCustomerExtDto.addressName': [
      { required: true, message: '请输入地址说明', trigger: 'blur' },
      { max: 10, message: '地址说明不能超过10个字符', trigger: 'blur' }
    ]
  },
  fileList: [], // 上传文件列表
  picList: [] // 上传文件列表
})
const { form, dialogParam, selectOptionObj, rules, fileList, picList } =
  toRefs(data)
const customerId = ref(router.currentRoute.value.query.customerId) //客户id
const formCol = ref(12)
const formGutter = ref(20)
const formRef = ref()
const companyOptions = ref([])
const taxTreeData = ref([])
const parentOptions = ref([]) //所属企业数据
const verifyInfoData = ref({}) //校验用的数据
const btnLoading = ref(false)
const props = defineProps({
  id: {
    type: String,
    default: ''
  }
})
/**
 * 客户类别
 */
const customerTypeChange = async val => {}

/***************************业务流程 模块 start****************************************************************/
const examineParam = ref({}) //审批弹窗参数
const isExamine = ref(true) //流程是判断是否走审批按钮
const flowOptions = ref([]) //该业务的流程数据
const isCanStart = ref(true) // 判断该业务是否可以审批发起
/*****审批模块  start*** */
/**
 * 提交审批 按钮
 */
const handleExamine = () => {
  if (!examineParam.value.businessId) {
    proxy.$modal.msgWarning('请重新发起审批')
    return false
  }
  console.info('我是审批')

  examineParam.value.businessName = form.value.bizCustomerAddDto.customerName //项目名称

  examineParam.value.categoryCode = '2' //分类编码
  examineParam.value.visible = true
  console.log('examineParam.value', examineParam.value)
}
// 关闭
const handleClose = type => {
  switch (type) {
    case 'examine':
      //弹出框关闭
      examineParam.value.visible = false

      close()
      break
    case 'initiate':
      //审批 发起成功
      examineParam.value.visible = false
      close()
      break
  }
}
/*****审批模块  end*** */
/*****审批模块  end*** */
/**
 * 业务流程整体思路：
 * 1.查询该业务是否有流程
 * 2.根据该业务流程来判断
 * * 2.1没有流程-提示不能新建数据
 * * 2.2只有一条流程时，则不弹出框流程提交审核按钮隐藏，直接保存(得到返回的业务id) 现实下一环节人的显示及弹出框 -再发起
 * * 2.3多条流程时，点击保存(得到返回的业务id) ，再点击提交审核按钮，弹出框现实流程，直接保存(得到返回的业务id) 现实下一环节人的显示及弹出框 -再发起
 * @param {*} type  业务类型 项目是1 订单业务2    客户模块业务3
 */
const initFlowFn = async type => {
  // 1.查询该业务是否有流程
  let comRes = await listProcess({
    pageNum: 1,
    pageSize: 9999,
    category: type
  })
  flowOptions.value = comRes.rows || []
  // 2.根据
  if (JSON.stringify(flowOptions.value) == '[]') {
    // 新建页面
    proxy.$modal.msgError('该业务没有流程，无法提交审批')
  } else if (flowOptions.value.length == 1) {
    //2.2 流程只有一个，只有一条流程时，则不弹出框流程提交审核按钮隐藏，直接点击保存
    // isExamine.value = true
    if (customerId.value != '' && customerId.value != null) {
      proxy.$nextTick(() => {
        handleExamine()
      })
    }
  } else {
    //2.3多条流程时
    handleExamine()
  }
}
// 编辑页面的时候 -》根据业务查询审批状态
const getBusinessProStatusFn = async () => {
  let statusRes = await getBusinessProStatus({ businessId: customerId.value })
  if (statusRes.data.canStart) {
    // canStart false时 不能发起，true则可以发起
    initFlowFn('2')
  } else {
    proxy.$modal.msgWarning('当前客户，无法发起审批')
  }
}
/***************************业务流程 模块 end****************************************************************/

/**
 * 根据当前是新增或者编辑来判断是否获取流程
 */
const juageFlow = () => {
  save().then(async res => {
    // 判断当前审批状态
    await getBusinessProStatusFn()
  })
}

watch(
  () => props.id,
  val => {
    if (
      (val && !!location.href.match(/detail/)) ||
      (val && !!location.href.match(/workDetail/))
    ) {
      console.info('我是watch')
      customerId.value = val
      // 待办详情-访问
      examineParam.value.businessId = val
      isExamine.value = false
    }
  },
  {
    immediate: true
  }
)

/**
 * 失去焦点的时候校验税号
 * @param val
 */
const checkTaxcode = () => {
  btnLoading.value = true
  return new Promise((resolve, reject) => {
    let isUniqueTaxCode = false
    let taxCode = form.value.bizCustomerAddDto.customerTaxcode

    // 新增
    if (router.currentRoute.value.query.flag == 'add') {
      checkCustomerTaxCode(taxCode)
        .then(res => {
          if (res.data != null) {
            proxy.$modal.msgError('已存在相同税号')
            return
          } else {
            isUniqueTaxCode = true
            resolve(isUniqueTaxCode)
          }
        })
        .finally(() => {
          btnLoading.value = false
        })
    } else {
      let verifyTaxCode = verifyInfoData.value.bizCustomerAddDto.customerTaxcode
      if (taxCode != verifyTaxCode) {
        checkCustomerTaxCode(taxCode)
          .then(res => {
            if (res.data != null) {
              proxy.$modal.msgWarning('税号已存在')
              return
            } else {
              isUniqueTaxCode = true
              resolve(isUniqueTaxCode)
            }
          })
          .finally(() => {
            btnLoading.value = false
          })
      } else {
        isUniqueTaxCode = true
        btnLoading.value = false
        resolve(isUniqueTaxCode)
      }
    }
  })
}

const orgChange = val => {
  //归属人员清空
  form.value.bizCustomerAddDto.userId = ''
}

// 上传合同
async function handleFileChange(params, type) {
  let formData = new FormData()
  formData.append('file', params.file)
  try {
    // 文件
    if (type == 'file') {
      // 限制只能上传一个文件
      if (fileList.value.length == 1) {
        proxy.$modal.msgWarning('只能上传一个文件')
        return
      }
    }
    // 照片
    if (type == 'pic') {
      // 限制只能上传一个文件
      if (picList.value.length == 1) {
        proxy.$modal.msgWarning('只能上传一个文件')
        return
      }
    }
    const res = await uploadFile(formData)
    if (res.code === 200 && res.data) {
      if (type == 'file') {
        fileList.value.push(res.data)
        form.value.bizCustomerExtDto.agentAgreementFileName = res.data.fileName
      }
      if (type == 'pic') {
        picList.value.push(res.data)
        form.value.bizCustomerExtDto.agentStarPicName = res.data.fileName
      }
    }
  } catch (error) {
    console.log(error)
    proxy.$modal.msgError(error)
  }
}

// 删除文件
async function delFileName(index, type) {
  try {
    proxy.$modal.confirm('是否删除该文件').then(async () => {
      if (type == 'file') {
        const file = fileList.value[index]
        const res = await delFile(file.fileName)
        if (res.code === 200) {
          form.value.bizCustomerExtDto.agentAgreementFileName = ''
          fileList.value.splice(index, 1)
          proxy.$modal.msgSuccess(res.data)
        }
      }
      if (type == 'pic') {
        const file = picList.value[index]
        const res = await delFile(file.fileName)
        if (res.code === 200) {
          form.value.bizCustomerExtDto.agentStarPicName = ''
          picList.value.splice(index, 1)
          proxy.$modal.msgSuccess(res.data)
        }
      }
    })
  } catch (error) {
    console.log(error)
    proxy.$modal.msgError(error)
  }
}

/**
 * 数电配置change
 */
function digitalChange(val) {
  if (val == 1) {
  } else {
    form.value.bizCustomerExtDto.digitalInfo = undefined
  }
}

/**
 * 状态修改change
 */
function statusChange() {
  if (router.currentRoute.value.query.flag == 'update') {
    form.value.bizCustomerAddDto.statusUpdateTime = formatDate(new Date())
  }
}

/**
 * 获取归属公司数据
 * @returns {Promise<void>}
 */
async function getCompany() {
  if (userStore.user.orgId !== 484) {
    // 所属单位列表
    commonStore.getCompanyData().then(data => {
      companyOptions.value = data
    })
  } else {
    //   无权限的所属公司
    let response = await treeselectNoPriv({ deptType: 1 })
    companyOptions.value = response.data
  }
}

/**
 * 所属企业模糊搜索
 * @param val 当前输入的值
 */
function queryCustomer(val) {
  if (!val) {
    return
  }
  let params = {
    pageSize: 10,
    customer: val
  }
  getListByCustomerName(params).then(res => {
    parentOptions.value = res.data
  })
}

/**
 * 初始化方法
 */
async function init() {
  console.info(router.currentRoute.value.query.customerId)

  // 归属公司数据
  await getCompany()

  // 获取税务机关下拉数据
  commonStore.getTaxTreeData().then(data => {
    taxTreeData.value = data
  })
  // flag==add新增
  if (router.currentRoute.value.query.flag == 'add') {
    // 默认归属公司
    form.value.bizCustomerAddDto.orgId = userStore.user.orgId
    form.value.bizContactDto.orgId = userStore.user.orgId
    await getDefaultUserInfo(userStore.user.userId, userStore.user.orgId)
  } else {
    //flag==update 编辑方法
    examineParam.value.businessId = router.currentRoute.value.query.customerId
    // 获取客户信息
    getCustomerInfoData()
  }
}

init()

/**
 * 根据当前用户回填归属人员表单
 */
async function getDefaultUserInfo(userId, orgId) {
  let id = ''
  if (userId) {
    id = userId
  } else {
    //获取当前用户id
    id = userStore.user.userId
  }
  //获取部门人员数据
  const deptUserData = await commonStore.getUseTreeData({ deptId: orgId })

  //根据当前用户id获取uuid
  let obj = getTreeNodeByParam(deptUserData, id, 'id', [])
  console.info('obj----------', obj)
  selectOptionObj.value.userId = obj
  form.value.bizCustomerAddDto.userId = obj[0].uuid
}

/**
 * 城市选择change事件
 * @param val
 */
function cityChange(val) {
  console.info('val', val)
}

/**
 * 获取客户信息
 */
function getCustomerInfoData() {
  console.info('我是init')
  let id = router.currentRoute.value.query.customerId || customerId.value
  getCustomerEditInfo(id).then(res => {
    let obj = JSON.parse(JSON.stringify(res.data))
    // 转换城市代码
    if (obj.bizCustomerAddDto.cityCode != null) {
      obj.bizCustomerAddDto.cityCode = obj.bizCustomerAddDto.cityCode.split(',')
    }
    // 转换星级字段属性
    if (obj.bizCustomerAddDto.starRating != null) {
      obj.bizCustomerAddDto.starRating = parseInt(
        obj.bizCustomerAddDto.starRating
      )
    }
    //转换所属税务机关属性
    if (obj.bizCustomerAddDto.taxdeptCode != null) {
      obj.bizCustomerAddDto.taxdeptCode = parseInt(
        obj.bizCustomerAddDto.taxdeptCode
      )
    }
    //获取所属企业信息
    if (obj.bizCustomerAddDto.parentId != null) {
      getCustomerInfo(obj.bizCustomerAddDto.parentId).then(res => {
        queryCustomer(res.data.vo.customerName)
      })
    }
    getDefaultUserInfo(
      obj.bizCustomerAddDto.userId,
      ''
      // obj.bizCustomerAddDto.orgId
    )
    // 代账文件
    if (
      obj.bizCustomerExtDto.agentAgreementFile != null &&
      obj.bizCustomerExtDto.agentAgreementFile.length > 0
    ) {
      obj.bizCustomerExtDto.agentAgreementFileName =
        obj.bizCustomerExtDto.agentAgreementFile[0].fileName
      fileList.value = obj.bizCustomerExtDto.agentAgreementFile
    }
    // 代账照片
    if (
      obj.bizCustomerExtDto.agentStarPic != null &&
      obj.bizCustomerExtDto.agentStarPic.length > 0
    ) {
      obj.bizCustomerExtDto.agentStarPicName =
        obj.bizCustomerExtDto.agentStarPic[0].fileName
      picList.value = obj.bizCustomerExtDto.agentStarPic
    }

    // 合作产品
    if (obj.bizCustomerExtDto.agentBusinessTypeId != null) {
      obj.bizCustomerExtDto.agentBusinessTypeId =
        obj.bizCustomerExtDto.agentBusinessTypeId.split(',')
    }
    //客户类别
    obj.bizCustomerAddDto.customerType =
      obj.bizCustomerAddDto.customerType.split(',')

    form.value = obj
    verifyInfoData.value = JSON.parse(JSON.stringify(obj))

    if (
      obj.bizCustomerAddDto.flowStatus == '01' ||
      obj.bizCustomerAddDto.flowStatus == '02' ||
      obj.bizCustomerAddDto.flowStatus == '05'
    ) {
      isCanStart.value = false
    } else {
      isCanStart.value = true
    }
  })
}

const handleSave = () => {
  return new Promise((resolve, reject) => {
    try {
      proxy.$refs.formRef.validate((valid, fields) => {
        if (valid) {
          let data = JSON.parse(JSON.stringify(toRaw(form.value)))
          if (form.value.bizCustomerAddDto.cityCode) {
            // 转换所在区域城市编码
            data.bizCustomerAddDto.cityCode =
              form.value.bizCustomerAddDto.cityCode.join(',')
          }
          if (form.value.bizCustomerAddDto.userId) {
            // 获取查询到的user数据对象
            let userObj = getUniqueUserId(
              selectOptionObj.value['userId'],
              form.value.bizCustomerAddDto.userId
            )
            //获取userid
            data.bizCustomerAddDto.userId = userObj.id
            data.bizContactDto.userId = userObj.id

            //获取deptId
            data.bizCustomerAddDto.deptId = userObj.deptId
            data.bizContactDto.deptId = userObj.deptId

            //   获取userName
            data.bizCustomerAddDto.userName = userObj.label
            data.bizContactDto.userName = userObj.label
          }
          // 企业类型（1客户 2供应商）
          data.bizContactDto.entType = '1'
          data.bizContactDto.isChiefly = '1'
          // 如果为代账公司
          if (data.bizCustomerAddDto.customerType.includes('4')) {
            data.bizCustomerExtDto.isAgent = '1'
          }
          data.bizCustomerAddDto.customerType =
            form.value.bizCustomerAddDto.customerType.join(',')

          // 修改
          updateCustomer(data).then(async res => {
            resolve()
          })
        } else {
          proxy.$nextTick(() => {
            document.getElementsByClassName('is-error')[0].scrollIntoView({
              behavior: 'smooth',
              block: 'center'
            })
          })
        }
      })
    } catch (e) {
      reject(e)
    }
  })
}

defineExpose({
  handleSave
})

/**
 * 保存方法
 */
function save() {
  return new Promise((resolve, reject) => {
    if (
      form.value.bizCustomerExtDto.isDigital == 1 &&
      !form.value.bizCustomerExtDto.digitalInfo
    ) {
      proxy.$modal.msgError('请选择数电信息')
      reject()
      return
    }
    proxy.$refs.formRef.validate(async (valid, fields) => {
      if (valid) {
        let data = JSON.parse(JSON.stringify(toRaw(form.value)))
        if (form.value.bizCustomerAddDto.cityCode) {
          // 转换所在区域城市编码
          data.bizCustomerAddDto.cityCode =
            form.value.bizCustomerAddDto.cityCode.join(',')
        }
        if (form.value.bizCustomerAddDto.userId) {
          // 获取查询到的user数据对象
          let userObj = getUniqueUserId(
            selectOptionObj.value['userId'],
            form.value.bizCustomerAddDto.userId
          )
          //获取userid
          data.bizCustomerAddDto.userId = userObj.id
          data.bizContactDto.userId = userObj.id

          //获取deptId
          data.bizCustomerAddDto.deptId = userObj.deptId
          data.bizContactDto.deptId = userObj.deptId

          //   获取userName
          data.bizCustomerAddDto.userName = userObj.label
          data.bizContactDto.userName = userObj.label
        }
        // 企业类型（1客户 2供应商）
        data.bizContactDto.entType = '1'
        data.bizContactDto.isChiefly = '1'
        // 如果为代账公司
        if (data.bizCustomerAddDto.customerType.includes('4')) {
          data.bizCustomerExtDto.isAgent = '1'
          data.bizCustomerExtDto.agentBusinessTypeId =
            form.value.bizCustomerExtDto.agentBusinessTypeId
              .map(item => item)
              .join(',')
        }
        data.bizCustomerAddDto.customerType =
          form.value.bizCustomerAddDto.customerType.join(',')

        if (data.bizCustomerExtDto.address) {
          data.bizContactDto.address = data.bizCustomerExtDto.address
        }
        if (data.bizCustomerExtDto.addressName) {
          data.bizContactDto.addressName = data.bizCustomerExtDto.addressName
        }
        if (!customerId.value) {
          checkTaxcode().then(async res => {
            // 新增
            await createCustomer(data).then(async res => {
              proxy.$modal.msgSuccess(res.msg)
              examineParam.value.businessId = res.data
              customerId.value = res.data
              //   判断是否获取流程
              if (form.value.bizCustomerAddDto.customerType.includes('2')) {
                // await juageFlow()
                resolve()
              } else {
                close()
              }
            })
          })
        } else {
          checkTaxcode().then(async res => {
            //   获取联系人姓名
            data.bizContactDto.contactName =
              form.value.bizCustomerAddDto.mainContactName
            // 修改
            await updateCustomer(data).then(async res => {
              proxy.$modal.msgSuccess(res.msg)
              examineParam.value.businessId =
                router.currentRoute.value.query.customerId
              //   判断是否获取流程
              if (form.value.bizCustomerAddDto.customerType.includes('2')) {
                // await juageFlow()
                resolve()
              } else {
                console.info('ajkd')
                close()
              }
            })
          })
        }
      } else {
        proxy.$nextTick(() => {
          document.getElementsByClassName('is-error')[0].scrollIntoView({
            behavior: 'smooth',
            block: 'center'
          })
        })
      }
    })
  })
}

/**
 * 关闭方法
 */
function close() {
  console.info('123')
  useTagsViewStore().delView(router.currentRoute.value)
  router.go(-1)
}

/**
 * 弹窗选取获取选中的值
 * @param val
 *  type 业务类型
 *     selectData 选中的数据[{value: 1, label: '王晓易', $treeNodeId: 2}]
 *     labelData 选中的数据label ['王晓易']
 *     defaultCheckedKeys 选中的数据id [1]
 *     dialogVisible: false 弹出框的关闭
 */
function selectData(val) {
  console.info('val', val)
  //归属人员
  if (val.type == 'userId') {
    if (!val.selectData.length) {
      form.value.bizCustomerAddDto[val.type] = ''
    } else {
      selectOptionObj.value[val.type] = val.selectData
      form.value.bizCustomerAddDto[val.type] = val.defaultCheckedKeys.join(',')
    }
  }
}

/**
 * 归属人员input获取焦点事件
 */
function userInputFocus() {
  dialogParam.value.type = 'userId'
  dialogParam.value.title = '选择归属人员'
  dialogParam.value.dataType = 'person'
  dialogParam.value.multiple = false
  dialogParam.value.checkStrictly = false
  dialogParam.value.nodeKey = 'uuid'
  dialogParam.value.apiParams = { deptId: form.value.bizCustomerAddDto.orgId }

  // selectOptionObj.value['userId'] = []
  if (
    form.value.bizCustomerAddDto['userId'] &&
    form.value.bizCustomerAddDto['userId'].length
  ) {
    dialogParam.value.isDialog = true
    dialogParam.value.defaultCheckedKeys = [
      form.value.bizCustomerAddDto['userId']
    ]
  } else {
    dialogParam.value.isDialog = true
    dialogParam.value.defaultCheckedKeys = []
  }
}
</script>
<style lang="scss" scoped></style>
